/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2023-10-26 11:10:06
 * @LastEditors: TT
 * @LastEditTime: 2023-10-27 15:59:08
 */

import 'package:flutter/material.dart';
import 'package:hzy_project_template/config/config_index.dart';
import 'package:hzy_project_template/controllers/user_c.dart';
import 'package:hzy_project_template/pages/my/routers/routers_index.dart';
import 'package:hzy_project_template/utils/utils_index.dart';

class MyWidget {
  /// 配置用户信息 之 重要信息
  configUserInfoTopWidget({
    TapItemCallback? tapItemCallback,
  }) {
    Widget body = GetBuilder<UserC>(
      builder: (controller) {
        List<HzyNormalItemModel> list = [
          HzyNormalItemModel(
            leftWidget: configUserInfoTopLeftWidget(
              title: NoteLauncIdConfig.nickName.tr,
              msg: controller.user?.nickName ?? NoteLauncIdConfig.appName.tr,
            ),
            rightType: 1,
            router: MyModuleRouterS.myChangeInfo,
          ),
          HzyNormalItemModel(
            leftWidget: configUserInfoTopLeftWidget(
              title: NoteLauncIdConfig.profiles.tr,
              msg: controller.user?.profiles ??
                  NoteLauncIdConfig.clickSettings.tr,
            ),
            rightType: 1,
            router: MyModuleRouterS.myChangeInfo,
          ),
          HzyNormalItemModel(
            leftWidget: configUserInfoTopLeftWidget(
              title: NoteLauncIdConfig.account.tr,
              msg: controller.user?.account ?? NoteLauncIdConfig.appName.tr,
            ),
            isCanTap: false,
          ),
        ];

        return configUserInfoListWidget(
          list: list,
          tapItemCallback: tapItemCallback,
        );
      },
    );
    return body;
  }

  /// 创建用户信息信息列表
  static configUserInfoListWidget({
    required List<HzyNormalItemModel> list,
    TapItemCallback? tapItemCallback,
    TextStyle? leftStyle,
    TextStyle? rightStyle,
  }) {
    Widget bt = Column(
      children: [
        ...List.generate(
          list.length,
          (index) {
            HzyNormalItemModel itemModel = list[index];
            itemModel.backGroudColor = null;
            itemModel.padding = const EdgeInsets.symmetric(
              vertical: 15,
              horizontal: 15,
            );
            itemModel.leftStyle = leftStyle;
            itemModel.rightStyle = rightStyle;

            return HzyNormalItemWidget(
              itemModel: itemModel,
              tapItemCallback: (itemModel, iex) {
                tapItemCallback?.call(itemModel, index);
              },
            );
          },
        )
      ],
    );
    bt = Container(
      margin: EdgeInsets.symmetric(
        horizontal: 10.w,
      ),
      decoration: BoxDecoration(
        color: PageNormalConfig().navBackgroundColor,
        borderRadius: BorderRadius.circular(
          16.r,
        ),
      ),
      child: bt,
    );
    return bt;
  }

  /// 创建重要用户信息 左边视图
  static configUserInfoTopLeftWidget({
    required String title,
    required String msg,
  }) {
    Widget body = Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        configUserInfoItemLeftTitleWidget(
          title: title,
        ),
        Gaps.vGap2,
        Text(
          msg,
          style: HzyTextStyle.fontRegular(
            size: 14.sp,
            color: HzyCommonColor().col666666,
          ),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
      ],
    );
    return body;
  }

  static configUserInfoItemLeftTitleWidget({
    required String title,
  }) {
    return Text(
      title,
      style: FontConfig.fontBold16Black,
    );
  }
}
